<template>
    <van-row style="padding-top:10px;padding-bottom:10px;e: 16px;background-color: beige;box-sizing: border-box;">
        <van-col span="8" offset="2">
            <img :src="business.businessImg" style="width: 100%;"/>
        </van-col>
        <van-col span="12" offset="2">
            <div>商家名称：{{business.businessName}}</div>
            <div>商家简介：{{business.businessExplain}}</div>
            <div>商家地址：{{business.businessAddress}}</div>
        </van-col>
    </van-row>
   <van-row style="margin-top: 10px;">
    <van-col span="24">
      <!-- 查询餐品信息 -->
        <van-list
            v-model:loading="loading"
            :finished="finished"
            finished-text="没有更多了"
            @load="getFoodByBid"
          >
            <!-- 列表项 -->
            <van-row style="margin-top: 5px"  v-for="food in foodList" :key="food.foodId">
              <van-col :span="8" align="center" >
                  <img :src="food.foodImg" style="width: 60%;height: 60px;">
              </van-col>
              <van-col :span="13" align="left" >
                  <div style="font-size: 16px;">{{food.foodName}}</div>
                  <div style="font-size: 12px;">￥{{food.foodPrice}}</div>
                  <div style="font-size: 12px;">{{food.foodExplain}}</div>
              </van-col>
              <van-col :span="3" align="right" >
                  <svg t="1732846529248" class="icon" viewBox="0 0 1024 1024" version="1.1" 
                   xmlns="http://www.w3.org/2000/svg" p-id="31196" width="32" height="32">
                   <path d="M962.079334 545.28l61.44-352.768c1.536-7.68-0.512-14.848-5.632-20.992-5.12-5.632-12.288-9.216-19.456-9.216H279.583334c-14.336 0-25.6 11.264-25.6 25.6s11.264 25.6 25.6 25.6h688.64l-53.248 304.128-631.296 84.48L184.351334 137.728c-1.536-7.68-6.656-14.336-13.824-17.408l-133.632-66.56c-12.8-6.144-28.16-1.024-34.304 11.776-6.144 12.8-1.024 28.16 11.776 34.304l122.368 60.416L266.271334 765.44c2.56 11.776 12.8 20.48 25.088 20.48h663.552c14.336 0 25.6-11.264 25.6-25.6s-11.264-25.6-25.6-25.6H311.839334l-17.408-81.92 645.632-86.016c11.264-2.048 19.968-10.752 22.016-21.504z" fill="#d81e06" p-id="31197"></path><path d="M395.295334 896m-51.2 0a51.2 51.2 0 1 0 102.4 0 51.2 51.2 0 1 0-102.4 0Z" fill="#d81e06" p-id="31198"></path><path d="M866.335334 896m-51.2 0a51.2 51.2 0 1 0 102.4 0 51.2 51.2 0 1 0-102.4 0Z" fill="#d81e06" p-id="31199"></path></svg>
              </van-col>
            </van-row>
        </van-list>
    </van-col>
  </van-row>
</template>

<script setup>
import { ref,getCurrentInstance, onMounted } from 'vue';
import {showNotify } from 'vant';

  const {proxy} = getCurrentInstance();

  const loading = ref(false);  //加载的状态  查询之前置为true  查询完毕置为false
  const finished = ref(false);  //所有的数据全部查完之后置为true

  const bid = ref(null);  //商家id值

  const foodList = ref([]);  //当前商家的所有餐品

  //根据商家id查询餐品列表
  const getFoodByBid = ()=>{

        if(!bid.value){
            showNotify({ message: '无商家编号无法查询' });
            return;
        }

        loading.value = true;

        proxy.$axios({
          method: 'get',
          url: '/food/business/'+bid.value
        }).then(res=>{
          let resultBean = res.data;
          if(resultBean.code == 200){
            foodList.value = resultBean.data;

            loading.value = false;
            finished.value = true;

          }else{
            showNotify({ message: resultBean.msg });
          }
        }).catch(error=>{
          showNotify({ message: error.message });
        })
    }

  const business = ref({});

  const getBusinessById = ()=>{
    proxy.$axios({
          method: 'get',
          url: '/business/'+bid.value
        }).then(res=>{
          let resultBean = res.data;
          if(resultBean.code == 200){
            business.value = resultBean.data;
          }else{
            showNotify({ message: resultBean.msg });
          }
        }).catch(error=>{
          showNotify({ message: error.message });
        })
  }

  onMounted(()=>{
    console.log('*********',proxy.$route.params.bid);
    //接收路由传递的参数   商家的id值   用商家的id值查询这个商家所有的餐品
    bid.value = proxy.$route.params.bid;
    getBusinessById();
  })

</script>

<style>
</style>